package org.sucri.floxs.html;

/**
 * Created by IntelliJ IDEA.
 * User: Wen Yu
 * Date: Aug 21, 2007
 * Time: 7:44:40 PM
 * To change this template use File | Settings | File Templates.
 */
import java.io.*;
import org.antlr.stringtemplate.*;
import org.sucri.floxs.servlet.User;

public class TemplatePage
{
  private User mUser = null;
  
  private StringTemplateGroup mTemplateGroup = null;

  public TemplatePage(String name, String dir, User user)
  {
    mTemplateGroup = new StringTemplateGroup(name, dir);
    mUser          = user;
  }
  public String generate(String page, TemplateDictionary dic) throws IOException
  {
    StringTemplate st = dic.setAttributes(mTemplateGroup.getInstanceOf(page));

    // different user setting                                                   
    String userinfo = null;
    if (mUser == null)
    {
      userinfo = "<p id='user-info'class='welcome'>Welcome, Guest. Please <a href='javascript:login_user()'>login</a> or <a href='javascript:register_new_user()'>register</a>.</p>";
    }
    else
    {
      userinfo = "<p id='user-info'class='welcome'>Welcome, " + mUser.getName() + ". You're Ready to play!";
      st.removeAttribute("script_login");
      st.removeAttribute("script_register");
    }
    st.setAttribute("user_info", userinfo);
    return st.toString();
/*
    String extjs =
        "<link rel=\"stylesheet\" type=\"text/css\" href=\"/sucri/css/extjs/ext-all.css\"/>\n" +
        "<link rel=\"stylesheet\" type=\"text/css\" href=\"/sucri/css/extjs/xtheme-aero.css\"/>\n" +
        //"<link rel=\"stylesheet\" type=\"text/css\" href=\"/sucri/css/extjs/form.css\"/>\n" +
        "<script type=\"text/javascript\" src=\"/sucri/js/ext-base.js\"></script>\n" +
        "<script type=\"text/javascript\" src=\"/sucri/js/ext-all-debug.js\"></script>\n";
    
    String script_login = "<script type=\"text/javascript\" src=\"/sucri/js/fluxs/login_dlg.js\"></script>";

    String login_container = "<div id=\"login-form\"></div>";

    String menu_top =
        "    <ul class=\"leftmenu\">\n" +
        "\t\t<li class=\"Solutions\">$menu_top_1$</li>\n" +
        "\t\t<li><a href=\"#\">$menu_top_2$</a></li>\n" +
        "\t\t<li><a href=\"#\">$menu_top_3$</a></li>\n" +
        "\t\t<li><a href=\"#\">$menu_top_4$</a></li>\n" +
        "\t\t<li><a href=\"#\">$menu_top_5$</a></li>\n" +
        "\t\t<li class=\"clients\"><a href=\"#\">$menu_top_6$</a></li>\n" +
        "\t</ul>";

    String menu_section =
        "\t\t<h2>$section_title$</h2>\n" +
        "\t\t<ul>\n" +
        "\t\t\t<li><a href=\"#\"><span>$menu_section_1$</span></a></li>\n" +
        "\t\t\t<li><a href=\"#\"><span>$menu_section_2$</span></a></li>\n" +
        "\t\t\t<li><a href=\"#\"><span>$menu_section_3$</span></a></li>\n" +
        "\t\t\t<li><a href=\"#\"><span>$menu_section_4$</span></a></li>\n" +
        "\t\t\t<li><a href=\"#\"><span>$menu_section_5$</span></a></li>\n" +
        "\t\t\t<li><a href=\"#\"><span>$menu_section_6$</span></a></li>\n" +
        "\t\t\t<li><a href=\"#\"><span>$menu_section_7$</span></a></li>\n" +
        "\t\t</ul>";

    st.setAttribute("script_extjs", extjs);
    st.setAttribute("title", "TITLE");
    st.setAttribute("login", "login.js");
    st.setAttribute("login_container", login_container);
    st.setAttribute("resource", "/sucri/css/aquatic/");
    st.setAttribute("menu_section", menu_section);
    st.setAttribute("script_login", script_login);
    return st.toString();
*/
  }
}